﻿using DMC.Core.Models.Dto;
using DMC.Core.Models.Queries;
using DMC.Core.Models.VO;
using DMC.Core.Providers;
using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications;
using MiniFox.Platform.Applications.Auth;
using MiniFox.Platform.Exceptions;

namespace DMC.Core.Services.Impls
{
    [AutoResolve]
    public class ExcelExportService : ApiServiceBase, IExcelExportService
    {
        public ExcelExportService(SystemPrincipal principal) : base(principal)
        {
        }
        [AutoWired]
        protected IExcelExportProvider Provider { get; set; }

        public ResultObject<IEnumerable<ExcelExportVo>> Query(PagedQueryObject<ExcelExportQuery> request)
        {
            return this.Provider.Query(request);
        }

        public ExcelExportVo Item(string name)
        {
            return this.Provider.Item(name);
        }

        public ExcelExportVo Update(ExcelExportDto dto)
        {
            if (this.Provider.Update(dto))
                return this.Provider.Item(dto.Name);
            return null;
        }

        public void Remove(string name)
        {
            if (this.Provider.Remove(name))
                throw new PlatformException("ERR_OperateFail");
        }

        public ExcelExportVo Create(ExcelExportDto dto)
        {
            if (this.Provider.Create(dto))
                return this.Provider.Item(dto.Name);
            return null;
        }

    }
}
